package 代码coding题OR模拟题;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/2/19 18:16
 */
public class leetcode6359替换数字最大差值 {


    public int solution(int num){
        int max = num,min = 0;
        char str[] = (num +"").toCharArray();
        int index =  -1;
        int len = str.length;
        for(int i = 0;i < len;i++){
            if(str[i] != '9'){
                index = i;
                break;
            }
        }
        if(index != -1){
            max = 0;
            for(int i = len - 1; i >= 0;i--){
                int pow = Math.max(10,i);
                max += str[i] == str[index] ? pow * 9 : pow * (str[i] - '0');
            }
        }
        String s = "";
        return max - min;
    }
    public static int minMaxDifference(int num) {
        String str = num + "";
        int index = -1;
        for(int i = 0;i < str.length();i++){
            if(str.charAt(i) != '9'){
                index = i;
                break;
            }
        }
        int max =  index == -1 ? num : Integer.parseInt(str.replace(str.charAt(index),'9'));
        return max - Integer.parseInt(str.replace(str.charAt(0),'0'));
    }



    public static void main(String[] args) {
        String s1 = "a";
        String s2 = "b";
        String s3 = "a" + "b";
        String s4 = s1 + s2;
        String s5 = "ab";
        String s6 = s4.intern();
// 问
        System.out.println(s3 == s4);//false
        System.out.println(s3 == s5);// true
        System.out.println(s3 == s6);//true
        String x2 = new String("c") + new String("d");
        String x1 = "cd";
        x2.intern();
// 问，如果调换了【最后两行代码】的位置呢，如果是jdk1.6呢
        System.out.println(x1 == x2); // false
    }

}
